﻿using CompanyHubServer.DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace CompanyHubServer.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to your Company Store";

            var context = new HubContext();

            // Locate Active Company Hub app
            var cmpHub = context.Packages.Where(p => p.IsCompanyHub && p.IsActive && !p.IsHistory).FirstOrDefault();

            if (cmpHub != null)
            {
                ViewBag.CompanyHub = cmpHub;

            }

            // Locate Active Certificate
            var token = context.AppTokens.Where(c => c.IsActive).FirstOrDefault();

            if (token != null)
            {
                ViewBag.AppToken = token;

            }

            return View();
        }

    }
}
